"""
主窗口
"""
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import qtawesome


class MainUI(QtWidgets.QMainWindow):

    def __init__(self):
        super().__init__()
        self.init_ui()
        self.leftLayout_ui()
        self.rightLayout_ui()
        self.ui_style()

    # 确定基本的框架布局
    def init_ui(self):
        self.setFixedSize(1160, 775)  # 设置主窗口固定大小

        # 设置主部件及布局
        self.main_widget = QtWidgets.QWidget()  # 设置窗口主部件
        self.main_layout = QtWidgets.QGridLayout()  # 创建主部件网格布局
        self.main_widget.setLayout(self.main_layout)  # 设置主部件布局为网格布局

        # 设置左部件及布局
        self.left_widget = QtWidgets.QWidget()  # 设置主部件里的左部件
        self.left_widget.setObjectName("left_widget")  # 设置左部件别名
        self.left_layout = QtWidgets.QGridLayout()  # 创建左部件的网格部件
        self.left_widget.setLayout(self.left_layout)  # 设置左部件为网格部件

        # 设置右部件及布局
        self.right_widget = QtWidgets.QWidget()  # 设置主部件里的右部件
        self.right_widget.setObjectName("right_widget")  # 设置右部件别名
        self.right_layout = QtWidgets.QGridLayout()  # 创建右部件的网格部件
        self.right_widget.setLayout(self.right_layout)  # 设置右部件为网格部件

        # 设置左右部件在主部件的网格位置
        self.main_layout.addWidget(self.left_widget, 0, 0, 1, 2)
        self.main_layout.addWidget(self.right_widget, 0, 2, 1, 10)

        # 设置QMainWindow的中心组件
        self.setCentralWidget(self.main_widget)  # 设置为窗口主部件

    # 框架左布局
    def leftLayout_ui(self):
        self.left_label0 = QtWidgets.QPushButton()
        # self.left_label0.setStyleSheet("background-color:blue;")
        self.left_label0.setFlat(True)
        self.left_label0.setEnabled(False)
        self.left_label1 = QtWidgets.QPushButton("选词")
        self.left_label1.setStyleSheet("color:blue;")
        self.left_label1.setFlat(True)
        self.left_label1.setEnabled(False)
        self.left_button1 = QtWidgets.QPushButton("TOP20W")
        self.left_button1.setObjectName("left_button1")
        self.left_button2 = QtWidgets.QPushButton("Test")
        self.left_button1.setObjectName("left_button2")

        self.left_layout.addWidget(self.left_label1, 0, 0)
        self.left_layout.addWidget(self.left_button1, 1, 0)
        self.left_layout.addWidget(self.left_button2, 2, 0)
        self.left_layout.addWidget(self.left_label0, 9, 0, 5, 1)

    def rightLayout_ui(self):

        #### 数据源
        # 创建表格
        # self.dataSource_tableWidget = QtWidgets.QTableWidget(3, 3)
        # 添加表格数据

        # Item = QtWidgets.QTableWidgetItem('Top20W:')
        # self.dataSource_tableWidget.setItem(0, 0, Item)
        # Item = QtWidgets.QTableWidgetItem('潜力词:')
        # self.dataSource_tableWidget.setItem(1, 0, Item)
        # labelButton1 = QtWidgets.QLabel("Top20W:")
        # labelButton2 = QtWidgets.QLabel("潜力词:")
        #
        # radioButton1 = QtWidgets.QRadioButton("PC")
        # radioButton2 = QtWidgets.QRadioButton("无线")
        #
        # radioButton3 = QtWidgets.QRadioButton("PC")
        # radioButton4 = QtWidgets.QRadioButton("无线")
        # dataSourceButton = QtWidgets.QPushButton("确定数据源")
        # dataSourceButton.setStyleSheet("background-color:#0984e3;color:white;margin:3px")
        #
        # self.dataSource_tableWidget.setCellWidget(0, 0, labelButton1)
        # self.dataSource_tableWidget.setCellWidget(1, 0, labelButton2)
        # self.dataSource_tableWidget.setCellWidget(0, 1, radioButton1)
        # self.dataSource_tableWidget.setCellWidget(0, 2, radioButton2)
        # self.dataSource_tableWidget.setCellWidget(1, 1, radioButton3)
        # self.dataSource_tableWidget.setCellWidget(1, 2, radioButton4)
        # self.dataSource_tableWidget.setCellWidget(2, 1, dataSourceButton)
        #
        # self.dataSource_tableWidget.item(0, 0).setFlags()
        # # 表格头的显示与隐藏
        # self.dataSource_tableWidget.verticalHeader().setVisible(False)
        # self.dataSource_tableWidget.horizontalHeader().setVisible(False)
        # # 设置表格头为伸缩模式
        # self.dataSource_tableWidget.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
        # self.dataSource_tableWidget.verticalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)
        # # 将表格设置为禁止编辑
        # self.dataSource_tableWidget.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
        # # 只显示横分割线，不显示竖分割线
        # self.dataSource_tableWidget.setShowGrid(False)
        # self.dataSource_tableWidget.setStyleSheet("border-bottom:1px solid #ecf0f1;")  #ecf0f1

        dataSource_widget = QtWidgets.QWidget()
        dataSource_layout = QtWidgets.QGridLayout()
        dataSource_label1 = QtWidgets.QLabel("Top20W:")
        dataSource_label2 = QtWidgets.QLabel("潜力词:")

        dataSource_radio1 = QtWidgets.QRadioButton("PC")
        dataSource_radio2 = QtWidgets.QRadioButton("无线")

        dataSource_radio3 = QtWidgets.QRadioButton("PC")
        dataSource_radio4 = QtWidgets.QRadioButton("无线")
        dataSource_Button = QtWidgets.QPushButton("确定数据源")

        dataSource_widget.setLayout(dataSource_layout)
        dataSource_layout.addWidget(dataSource_label1, 0, 0)
        dataSource_layout.addWidget(dataSource_radio1, 0, 1)
        dataSource_layout.addWidget(dataSource_radio2, 0, 2)
        dataSource_layout.addWidget(dataSource_label2, 1, 0)
        dataSource_layout.addWidget(dataSource_radio3, 1, 1)
        dataSource_layout.addWidget(dataSource_radio4, 1, 2)
        dataSource_layout.addWidget(dataSource_Button, 2, 1)
        dataSource_widget.setStyleSheet("background:white;")

        ############################################################

        # 树状图
        self.treeWidget = QtWidgets.QTreeWidget()  # 实例树状图
        self.treeWidget.setObjectName("treeWidget")
        self.treeWidget.headerItem().setText(0, "类目树状图")

        root1 = QtWidgets.QTreeWidgetItem(self.treeWidget)  # 树状图根节点1
        root1.setText(0, "root_name")  # 根节点1名称

        child_root1 = QtWidgets.QTreeWidgetItem(root1)  # 创建子节点1
        child_root1.setText(0, "child_root_name1")  # 子节点1名称
        para_list1 = ["alpha", "beta", "gama"]
        for i in range(len(para_list1)):
            child = QtWidgets.QTreeWidgetItem(child_root1)  # child of root
            child.setText(0, para_list1[i])

        child_root2 = QtWidgets.QTreeWidgetItem(root1)  # 创建子节点1
        child_root2.setText(0, "child_root_name2")  # 子节点1名称
        para_list2 = ["alpha", "beta", "gama"]
        for i in range(len(para_list2)):
            child = QtWidgets.QTreeWidgetItem(child_root2)  # child of root
            child.setText(0, para_list1[i])

        grandson_root1 = QtWidgets.QTreeWidgetItem(child_root2)  # 创建孙节点1
        grandson_root1.setText(0, "背景墙软包/床头套/工艺软包")  # 孙节点1名称
        para_list3 = ["alpha", "beta", "gama"]
        for i in range(len(para_list3)):
            child = QtWidgets.QTreeWidgetItem(grandson_root1)  # child of root
            child.setText(0, para_list3[i])

        ######################################################################

        # 表格
        # tableWidget = QtWidgets.QTableWidget(4, 4)
        self.tableWidget = QtWidgets.QTableWidget()
        self.tableWidget.setRowCount(4)
        self.tableWidget.setColumnCount(4)

        # 设置水平方向的表头标签与垂直方向上的表头标签，注意必须在初始化行列之后进行，否则，没有效果
        self.tableWidget.setHorizontalHeaderLabels(['一级类目', '二级类目', '三级类目', '关键词'])

        self.right_layout.setRowStretch(0, 1)
        self.right_layout.setRowStretch(1, 4)
        self.right_layout.setColumnStretch(0, 1)
        self.right_layout.setColumnStretch(1, 3)
        self.right_layout.setSpacing(1)
        self.right_layout.addWidget(dataSource_widget, 0, 0)
        self.right_layout.addWidget(self.treeWidget, 1, 0)
        self.right_layout.addWidget(self.tableWidget, 0, 1, 2, 1)

    def ui_style(self):
        self.left_widget.setStyleSheet('''

                           QWidget#left_widget{
                                background:yellow;
                            }
                        ''')

        self.right_widget.setStyleSheet('''

                           QWidget#right_widget{
                                background:blue;
                            }
                        ''')

        # self.main_widget.setStyleSheet('''
        #
        #            QWidget#main_widget{
        #                 background:black;
        #             }
        #         ''')

        # self.main_widget.setStyleSheet("background-color:black;");


def main():
    app = QtWidgets.QApplication(sys.argv)
    gui = MainUI()
    gui.show()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()
